package utils

import (
	"fmt"
	"strings"
	"github.com/anhoder/foxful-cli/model"

	sts "gitee.com/nidielaila/go-mf/internal/structs"
)

// GetViewFromSongs 从歌曲列表获取View
func GetViewFromSongs(songs []sts.Song) []model.MenuItem {
	var menus []model.MenuItem

	for _, song := range songs {
		var artists []string
		for _, artist := range song.Artists {
			artists = append(artists, artist.Name)
		}

		menus = append(menus, model.MenuItem{
			Title: ReplaceSpecialStr(song.Name), Subtitle: ReplaceSpecialStr(strings.Join(artists, ","))
		})
	}

	return menus
}

// GetViewFromAlbums 从歌曲列表获取View
func GetViewFromAlbums(albums []sts.Album) []model.MenuItem {
	var menus []model.MenuItem

	for _, album := range albums {
		var artists []string

		for _, artist := range album.Artists {
			artists = append(artists, artist.Name)
		}

		artistsStr := fmt.Sprintf("[%s]", strings.Join(artists, ","))

		menus = append(menus, model.MenuItem{
			Title: ReplaceSpecialStr(album.Name),
			Subtitle: ReplaceSpecialStr(artistsStr),
		})
	}

	return menus
}

// GetViewFromPlaylists 从歌单列表获取View
func GetViewFromPlaylists(playlists []sts.Playlist) []model.MenuItem {
	var menus []model.MenuItem

	for _, plylist := range playlists {
		menus = append(menus, model.MenuItem{
			Title: ReplaceSpecialStr(plylist.Name),
		})
	}

	return menus
}

// GetViewFromArtists 从歌手列表获取View
// TODO: